package edu.hawaii.examschd;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import edu.hawaii.examschd.Console;
import edu.hawaii.examschd.modules.CouchDB.CouchDB;

/**
 * A JUnit test for testing the Console for correctness.
 * 
 * @author John MacMillan
 */
public class TestConsole {

  Console testConsole;
  String error;

  /**
   * Create a Console to test.
   */
  public TestConsole() {
    String url = "127.0.0.1";
    int port = 5984;
    testConsole = new Console(new CouchDB());
  }

  /**
   * Test processInput method for correct handling of inputs.
   */
  @Test
  public void testSetTesting() {
    error = "testSetTesting failed: Expected true";
    assertTrue(error, testConsole.setTesting(true));
    error = "testSetTesting failed: Expected false";
    assertFalse(error, testConsole.setTesting(false));
  }

  /**
   * Test processInput method for correct handling of inputs.
   */
  @Test
  public void testProcessInput() {
    testConsole.setTesting(true);
    error = "testProcessInput failed: \"get-cal\" not recognized";
    assertEquals(error, testConsole.processInput("get-cal "), Console.COMMAND);
    error = "testProcessInput failed: \"get-exam\" not recognized";
    assertEquals(error, testConsole.processInput("get-exam"), Console.COMMAND);
  }

  /**
   * Test buildHelpMessage method for correctness.
   */
  @Test
  public void testBuildHelpMessage() {
    testConsole.setTesting(true);
    error = "testBuildHelpMessage failed: Help message does not contain all expected values";
    assertTrue(error, testConsole.buildHelpMessage().contains("Available"));
    assertTrue(error, testConsole.buildHelpMessage().contains("quit"));
    assertTrue(error, testConsole.buildHelpMessage().contains("execution"));
  }

  /**
   * Test getHelpMessage method for correctness.
   */
  @Test
  public void testGetHelpMessage() {
    testConsole.setTesting(true);
    error = "testGetHelpMessage failed: Help message does not contain all expected values";
    assertTrue(error, testConsole.getHelpMessage().contains("Available"));
    assertTrue(error, testConsole.getHelpMessage().contains("quit"));
    assertTrue(error, testConsole.getHelpMessage().contains("execution"));
  }
}